/**
 * Created by anzhen on 2017-6-8.
 */
class FIleIO {

    static writeFile(){
        new File("file").withWriter('utf-8') {
            writer -> writer.writeLine 'Hello World'
        }
    }

    static readFile() {
        def lines = new File("file").readLines('utf8')
        println lines
    }
    static eachLine() {
        new File("file").eachLine {
            line -> println "line : $line"
        }
    }
    static fileText() {
        File file = new File("file")
        println file.text
    }

    static fileProperty() {
        File file = new File("file")
        println file.absolute
        println file.absoluteFile
        println file.absolutePath
        println file.canonicalFile
        println file.length()
        println file.isFile()
        println file.isDirectory()

    }

    static create() {
        def file = new File("file_dir")
        if (!file.exists()) {
            file.mkdir()
        }
    }

    static copy() {
        def file = new File("file")
        def file_copy = new File("file_copy")
        file_copy<<file.text

    }

    static listDir() {
        def file = new File("file_dir")
        file.listFiles().each{
            eachFile-> println eachFile.absolutePath
        }
    }
    static listDirRecurse() {
        def file = new File("file_dir")
        file.eachFileRecurse{
            eachFile-> println eachFile.absolutePath
        }
    }

    static listRoot() {
        def file = new File("file_dir")
        file.listRoots().each{
            eachFile-> println eachFile.absolutePath
        }
    }

    static void main(String[] args) {
        listDirRecurse()
    }





}
